<?

$fill_id_utkani = $_POST['id_utkani_s'];

?>
<form action="<? echo redirect_str(PAGE_ADMIN_ROSTER); ?>" method="post">
  <label for="utkani_se_soupiskou">Utkání se soupiskou</label>
  <select class="text" id="utkani_se_soupiskou" name='id_utkani_s' size=1>
    <?
    $query = getMatchesWithPlayers();
    while($fetch = mysql_fetch_array($query)){
          $id = $fetch["id_utkani"];
          $text = DateFormat::format($fetch["datum"], DF_DDMMYYYYHHMM)."\t".$fetch["domaci"]." - ".$fetch["hoste"]."\t".$fetch["b_domaci"].":".$fetch["b_hoste"]; 
          echo "<option value='$id'>$text</option>";
    }
    ?>
  </select>
  <input class="button" type="submit" value="NAPLNIT FORMULÁŘ TOUTO SOUPISKOU">
</form>

<form action="<? echo redirect_str(PAGE_ADMIN_ROSTER).action(ACTION_SAVE_ROSTER); ?>" method="post">
  
  <fieldset>
    <legend>Nová soupiska</legend>
    
    <table class="panel-70">
      <tr>
        <td colspan="2" class="righted">Vytvořit soupisku pro utkání</td>
        <td colspan="7">
          <select class="text" name='s_id_utkani' size=1>
          <?
          $query = getMatchesPlayed();
          while($fetch = mysql_fetch_array($query)){
                $id = $fetch["id_utkani"];
                $text = DateFormat::format($fetch["datum"], DF_DDMMYYYYHHMM)."\t".$fetch["domaci"]." - ".$fetch["hoste"]."\t".$fetch["b_domaci"].":".$fetch["b_hoste"]; 
                echo "<option value='$id'>$text</option>";
          }
          ?>
          </select><br/><br/>
        </td>
      </tr>
      
      <tr>
        <th>post</th>
        <th>od začátku nastoupil</th>
        <th>B</th>
        <th>ŽK</th>
        <th>ČK</th>
        <th>hráče střídal</th>
        <th>B</th>
        <th>ŽK</th>
        <th>ČK</th>
      </tr>
      
      <?
      if($fill_id_utkani != ""){
        $querySoupiska = getSoupiskas($fill_id_utkani);
      }
      for($i=1; $i<=11; $i++) {
          
          if($fill_id_utkani != "") {
            $soup = mysql_fetch_array($querySoupiska);
            $fill_id_post = $soup['ID_POST'];
            $fill_id_hrac = $soup['ID_HRAC'];
            $fill_b = $soup['BRANKY'];
            $fill_zk = $soup['ZK'];
            $fill_ck = $soup['CK'];
            if(bylStridan($fill_id_hrac, $fill_id_utkani)){
              $queryStridajici = getStridajici($fill_id_hrac, $fill_id_utkani);
              $strid = mysql_fetch_array($queryStridajici);
              $fill_id_hrac_str = $strid['ID_HRAC'];
              $fill_b_str = $strid['BRANKY'];
              $fill_zk_str = $strid['ZK'];
              $fill_ck_str = $strid['CK'];
            } else {
              $fill_id_hrac_str = -1;
              $fill_b_str = 0;
              $fill_zk_str = 0;
              $fill_ck_str = 0;
            }
          } else {
            $fill_b = 0;
            $fill_b_str = 0;
          }
          echo "<tr>";
            echo "<td><select class='full text' name='s_id_post_$i' size=1>";
            $query = getPosts();
            while($fetch = mysql_fetch_array($query)){
                  $id = $fetch["id_post"];
                  $post = $fetch["zkratka"];
                  if($id == $fill_id_post) echo "<option value='$id' selected>$post</option>";
                  else echo "<option value='$id'>$post</option>";
            }
            echo "</select></td>";
            
            echo "<td><select class='full text' name='s_id_hrac_$i' size=1>";
            echo "<option value='-1'>...</option>";
            $query = getAllPlayers();
            while($fetch = mysql_fetch_array($query)){
                  $id = $fetch["id_hrace"];
                  $prijmeni = $fetch["prijmeni"];
                  $jmeno = $fetch["jmeno"];
                  if($id == $fill_id_hrac) echo "<option value='$id' selected>$prijmeni  $jmeno</option>";
                  else echo "<option value='$id'>$prijmeni  $jmeno</option>";
            }
            echo "</select></td>";
            
            echo "<td>";
              echo "<input size=1 type='text' class='text' name='s_b_$i' value='$fill_b'>";
            echo "</td>";
            
            echo "<td>";
              echo "<input type='checkbox' name='s_zk_$i' ".($fill_zk == 1?"checked":"").">";
            echo "</td>";
            
            echo "<td>";
               echo "<input type='checkbox' name='s_ck_$i' ".($fill_ck == 1?"checked":"").">";
            echo "</td>";
            
            echo "<td><select class='full text' name='s_id_hrac_str_$i' size=1>";
            echo "<option value='-1'>...</option>";
            $query = getAllPlayers();
            while($fetch = mysql_fetch_array($query)){
                  $id = $fetch["id_hrace"];
                  $prijmeni = $fetch["prijmeni"];
                  $jmeno = $fetch["jmeno"];
                  if($id == $fill_id_hrac_str) echo "<option value='$id' selected>$prijmeni  $jmeno</option>";
                  else echo "<option value='$id'>$prijmeni  $jmeno</option>";
            }
            echo "</select></td>";
            
            echo "<td>";
              echo "<input size=1 type='text' class='text' name='s_b_str_$i' value='$fill_b_str'>";
            echo "</td>";
            
            echo "<td>";
               echo "<input type='checkbox' name='s_zk_str_$i' ".($fill_zk_str == 1?"checked":"").">";
            echo "</td>";
          
            echo "<td>";
               echo "<input type='checkbox' name='s_ck_str_$i' ".($fill_ck_str == 1?"checked":"").">";
            echo "</td>";
          echo "</tr>";
      }
      ?>
      
      <tr>
        <td colspan="9">
        <div class="center">
            <input class="button" onmouseover="this.className='button_hover'" 
       			onmouseout="this.className='button'" type="submit" value="ULOŽIT">
       		<a class="button preloader" href="<? echo redirect_str(PAGE_ADMIN_ROSTER); ?>">ZRUŠIT</a>
        </div>
        </td>
      </tr>
    </table>
  </fieldset>
</form>